'''
Created on Apr 6, 2011

@author: riche
'''

class SizeMismatchError(Exception):
    pass

class BadStringValError(Exception):
    pass

class BitMap(object):
    '''
    classdocs
    '''

    def __init__(self, size, string_val=None):
        '''
        Constructor
        '''
        self._core = [False for i in range(0, size)]
        if string_val is not None:
            if len(string_val) > size:
                raise SizeMismatchError
            else:
                index = 0
                for bit in string_val:
                    if bit == '1':
                        self._core[index] = True
                    elif bit != '0':
                        raise BadStringValError
                    index += 1
                        
        
    def set(self, index):
        self._core[index] = True
        
    def isSet(self, index):
        return self._core[index]
    
    def serialize(self):
        ret_val = ''
        for bit in self._core:
            if bit is True:
                ret_val += '1'
            else:
                ret_val += '0'
        return ret_val
    
